package libs

import (
	"errors"
	"os"
	"path/filepath"
)

type AppInstallHelper struct {
	AppId   string
	VerName string
}

func NewAppInstallHelper(appid string, version string) *AppInstallHelper {

	helper := &AppInstallHelper{
		AppId:   appid,
		VerName: version,
	}

	return helper
}

func (c *AppInstallHelper) ParseIPA() (*AppInfo, error) {

	path := filepath.Join(`./static`, c.AppId, c.VerName, "ios.ipa")

	app, err := NewAppParser(path)
	if err != nil {
		return nil, err
	}

	return app, nil
}

func (c *AppInstallHelper) GetPListPath() (string, error) {
	path := filepath.Join(`./static`, c.AppId, c.VerName, "info.plist")

	if _, err := os.Stat(path); os.IsNotExist(err) {
		return "", errors.New(path + " 不存在")
	}

	return path, nil
}

func (c *AppInstallHelper) GetAppIcon() (string, error) {
	path := filepath.Join(`./static`, c.AppId, c.VerName, "icon.png")

	if _, err := os.Stat(path); os.IsNotExist(err) {
		return "", errors.New(path + " 不存在")
	}

	return path, nil
}
